package com.example.waterorder.controller;

import com.example.waterorder.dto.BuildingMap;
import com.example.waterorder.entity.Building;
import com.example.waterorder.tools.Result;
import com.example.waterorder.service.BuildingService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/building")
public class BuildingController {

    @Resource
    private BuildingService buildingService;

    @Operation(summary = "查询所有building，渲染到学生注册宿舍楼选择框")
    @GetMapping("/all")
    public Result selectAllBuildings(){
        List<Building> buildingList = buildingService.selectAllBuildings();
        return buildingList!=null?new Result(true,buildingList)
                :new Result(false);
    }

    @Operation(summary = "查询宿舍楼地图，距离及宿舍楼信息")
    @GetMapping("/map")
    public Result selectBuildingMap(@RequestParam("workerId") String workerId,
                                    @RequestParam("lng") String lng,
                                    @RequestParam("lat") String lat){
        List<BuildingMap> buildingMapList = buildingService.getAllBuildingMap(workerId, lng, lat);
        return buildingMapList!=null?new Result(true,buildingMapList)
                :new Result(false);
    }

    @Operation(summary = "查询所有building的name，渲染到学生注册宿舍楼选择框")
    @GetMapping("/names")
    public Result selectAllBuildingNames(){
        List<String> names = buildingService.selectAllBuildingsName();
        return names!=null?new Result(true,names)
                :new Result(false);
    }
}
